package com.xhwl.logistics.enums;

import com.xhwl.common.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Getter
@AllArgsConstructor
public enum VehicleRechargeTypeEnum {

    MONEY(1, "钱"),
    MONTH(2, "月"),
    DAY(3, "天"),
    HOUR(4, "小时"),
    NUMBER(5, "次");

    private Integer id;

    private String description;

    private static final Map<Integer, VehicleRechargeTypeEnum> map;
    private static final Map<Integer, VehicleRechargeTypeEnum> mapForKeTop;
    static {
        map = new HashMap<>();
        for (VehicleRechargeTypeEnum vehicleRechargeTypeEnum : VehicleRechargeTypeEnum.values()) {
            map.put(vehicleRechargeTypeEnum.getId(), vehicleRechargeTypeEnum);
        }

        mapForKeTop = new HashMap<>();
        mapForKeTop.put(0, MONEY);
        mapForKeTop.put(1, MONTH);
        mapForKeTop.put(2, DAY);
        mapForKeTop.put(3, HOUR);
        mapForKeTop.put(4, NUMBER);
    }

    public static VehicleRechargeTypeEnum toVehicleRechargeTypeEnum(Integer id) {
        return Optional.ofNullable(map.get(id)).orElseThrow(() -> new BusinessException("非法充值类型id，无法转换为充值类型枚举"));
    }

    public static VehicleRechargeTypeEnum toVehicleRechargeTypeEnumByKeTop(Integer id) {
        return Optional.ofNullable(mapForKeTop.get(id)).orElseThrow(() -> new BusinessException("非法科拓充值类型id，无法转换为充值类型枚举"));
    }

}
